package com.sykj.weichat.web;

import java.lang.ProcessBuilder.Redirect;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sykj.util.HttpsUtils;
@Controller
public class AppWeb {
   public static final String url = "https://open.weixin.qq.com/connect/oauth2/authorize";
   public static final String appid = "wx8fd7214426289b1f";
	public String  auth2Weichat(){
		Map<String, Object> map = new HashMap<>();
		map.put("appid", appid);
		map.put("redirect_uri", "http://a69a0406.ngrok.io/weichat/login/");//自己的登录路径
		map.put("response_type", "code");
		map.put("scope", "snsapi_base");
		map.put("state", "STATE#wechat_redirect");
		//String sendByHttp = HttpsUtils.sendByHttp(map, url);
		//System.out.println("sendByHttp="+sendByHttp);
		
		System.out.println("-*/-*-*-*-/*-/-" + url+toParams(map));
		return "redirect:"+url+toParams(map);
	}
 
   
    public static String toParams(Map<String, Object> map){
    Set keyset = map.keySet();
    StringBuilder sb = new StringBuilder("?");
    	for (Iterator i = keyset.iterator();i.hasNext();) {
			String key = (String) i.next();
			sb.append(key).append("=");
			sb.append(map.get(key));
		}
		return sb.toString();
    	
    }
	public static void main(String[] args) {
		AppWeb appWeb = new AppWeb();
		appWeb.auth2Weichat();
	}
}
